package com.qingluan.dd;

import java.util.ArrayList;
import java.util.HashMap;

import com.baidu.mapapi.BMapManager;
import com.baidu.mapapi.map.MapView;
import com.baidu.mapapi.search.MKSearch;
import com.qingluan.DataFormat.PersonTag;
import com.qingluan.Database.MissionDataBase;
import com.qingluan.Database.Personal_Info_database;
import com.qingluan.Database.TempDataBase;
import com.qingluan.arguments.ARGUMENTS;
import com.qingluan.dd.util.SystemUiHider;
import com.qingluan.server.BroadCastRecevier;
import com.qingluan.widget.DragListView;
import com.qingluan.widget.GestureListener;
import com.qingluan.widget.TimeHelper;
import com.qingluan.widget.DragListView.OnRefreshListener;
import com.qingluan.widget.DragListView.OnRefreshTailListener;

import android.annotation.TargetApi;
import android.app.Activity;
import android.app.AlertDialog;
import android.content.ContentValues;
import android.content.Context;
import android.content.DialogInterface;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.KeyEvent;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.AdapterView.OnItemLongClickListener;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;

/**
 * An example full-screen activity that shows and hides the system UI (i.e.
 * status bar and navigation/system bar) with user interaction.
 * 
 * @see SystemUiHider
 */
public class MissionListFullscreenActivity extends Activity {
	private DragListView my_missions;
	private TextView my_name , my_tag;
	private ImageView my_picture;
	private String uid;
	private String RE_mission_id;
	private DragListAdapter adapter;
	
	
	//context argu area
	private static Context context_this_activity;
	private static String Token = "INDEX";
	private Intent from_intent;
	private Intent intent_to_talkoing;
	private String tag  = this.getClass().getName();
	
	//map argu area
	BMapManager mBMapMan = null;
	MapView mMapView = null; 
	MKSearch Searcher ;
	
	
	
	/**
	 * Whether or not the system UI should be auto-hidden after
	 * {@link #AUTO_HIDE_DELAY_MILLIS} milliseconds.
	 */
	private static final boolean AUTO_HIDE = true;

	/**
	 * If {@link #AUTO_HIDE} is set, the number of milliseconds to wait after
	 * user interaction before hiding the system UI.
	 */
	private static final int AUTO_HIDE_DELAY_MILLIS = 3000;

	/**
	 * If set, will toggle the system UI visibility upon interaction. Otherwise,
	 * will show the system UI visibility upon interaction.
	 */
	private static final boolean TOGGLE_ON_CLICK = true;

	/**
	 * The flags to pass to {@link SystemUiHider#getInstance}.
	 */
	private static final int HIDER_FLAGS = SystemUiHider.FLAG_HIDE_NAVIGATION;

	/**
	 * The instance of the {@link SystemUiHider} for this activity.
	 */
	private SystemUiHider mSystemUiHider;
	
	//token area
	private String token_id;
	private String token_key;
		

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		context_this_activity = getApplicationContext();
		
		mBMapMan = new BMapManager(context_this_activity);
		mBMapMan.init("Ei38G5wOcSolTE7LXhDf0eNj", null);
		
		Log.d(tag, "token id : "+ token_id+" key:"+token_key);
		
		setContentView(R.layout.activity_mission_list_fullscreen);
		from_intent = getIntent();
		
		
		uid = getIntent().getExtras().getString("uid");
		token_id = getIntent().getExtras().getString("token_id");
		token_key = getIntent().getExtras().getString("token_key");
		Log.d("CACHE","uid " +uid);
		
		final View controlsView = findViewById(R.id.fullscreen_content_controls);
		final View contentView = findViewById(R.id.fullscreen_content);
		
		try{
			if(from_intent.getStringExtra("receive").equals("yes")){
				Token = "MISSION";
				RE_mission_id = from_intent.getStringExtra("mission_id");
			}
		}catch( NullPointerException e){
			
		}
		// Set up an instance of SystemUiHider to control the system UI for
		// this activity.
		mSystemUiHider = SystemUiHider.getInstance(this, contentView,
				HIDER_FLAGS);
		mSystemUiHider.setup();
		mSystemUiHider
				.setOnVisibilityChangeListener(new SystemUiHider.OnVisibilityChangeListener() {
					// Cached values.
					int mControlsHeight;
					int mShortAnimTime;

					@Override
					@TargetApi(Build.VERSION_CODES.HONEYCOMB_MR2)
					public void onVisibilityChange(boolean visible) {
						if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB_MR2) {
							// If the ViewPropertyAnimator API is available
							// (Honeycomb MR2 and later), use it to animate the
							// in-layout UI controls at the bottom of the
							// screen.
							if (mControlsHeight == 0) {
								mControlsHeight = controlsView.getHeight();
							}
							if (mShortAnimTime == 0) {
								mShortAnimTime = getResources().getInteger(
										android.R.integer.config_shortAnimTime);
							}
							controlsView
									.animate()
									.translationY(visible ? 0 : mControlsHeight)
									.setDuration(mShortAnimTime);
						} else {
							// If the ViewPropertyAnimator APIs aren't
							// available, simply show or hide the in-layout UI
							// controls.
							controlsView.setVisibility(visible ? View.VISIBLE
									: View.GONE);
						}

						if (visible && AUTO_HIDE) {
							// Schedule a hide().
							delayedHide(AUTO_HIDE_DELAY_MILLIS);
						}
					}
				});

		// Set up the user interaction to manually show or hide the system UI.
		contentView.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View view) {
				if (TOGGLE_ON_CLICK) {
					mSystemUiHider.toggle();
				} else {
					mSystemUiHider.show();
				}
			}
		});
		

		// Upon interacting with UI controls, delay any scheduled hide()
		// operations to prevent the jarring behavior of controls going away
		// while interacting with the UI.
		findViewById(R.id.dummy_button).setOnTouchListener(
				mDelayHideTouchListener);
		/*###############################
		 * my personal action 
		 * 
		 */
		Initialization();
	}

	@Override
	protected void onPostCreate(Bundle savedInstanceState) {
		super.onPostCreate(savedInstanceState);

		// Trigger the initial hide() shortly after the activity has been
		// created, to briefly hint to the user that UI controls
		// are available.
		delayedHide(100);
	}

	/**
	 * Touch listener to use for in-layout UI controls to delay hiding the
	 * system UI. This is to prevent the jarring behavior of controls going away
	 * while interacting with activity UI.
	 */
	View.OnTouchListener mDelayHideTouchListener = new View.OnTouchListener() {
		@Override
		public boolean onTouch(View view, MotionEvent motionEvent) {
			if (AUTO_HIDE) {
				delayedHide(AUTO_HIDE_DELAY_MILLIS);
			}
			return false;
		}
	};

	Handler mHideHandler = new Handler();
	Runnable mHideRunnable = new Runnable() {
		@Override
		public void run() {
			mSystemUiHider.hide();
		}
	};

	/**
	 * Schedules a call to hide() in [delay] milliseconds, canceling any
	 * previously scheduled calls.
	 */
	private void delayedHide(int delayMillis) {
		mHideHandler.removeCallbacks(mHideRunnable);
		mHideHandler.postDelayed(mHideRunnable, delayMillis);
	}
	
	
	public void  Initialization(){
		//#####################  initialization ####################
		
		
		my_missions = (DragListView)findViewById(R.id.my_mission_list_drag);
		adapter = new DragListAdapter(context_this_activity);
		my_missions.setAdapter(adapter);
		
		LayoutInflater inflater  =  (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);//LayoutInflater.from(context_this_activity);
		RelativeLayout headerView = (RelativeLayout) inflater.inflate(R.layout.widget_header_list, null);
		my_missions.addHeaderView(headerView);
		
		my_name = (TextView)findViewById(R.id.my_name);
		my_tag = (TextView) findViewById(R.id.my_tag);
		my_picture = (ImageView)findViewById(R.id.my_picture);
		try{
			if (from_intent.getStringExtra("receive").equals("yes")){
				ParaMissionFromWeb(adapter,RE_mission_id);
			}
		}catch (NullPointerException e){
			Log.d("MENU", "from index to this activity");
			ParaMissionFromDb(adapter,RE_mission_id);
		}
		
		//###############################################
		/*
		 * 
		 * do some important thing
		 */ 
		my_picture.setOnClickListener(new OnClickListener(){

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				Intent intent = new Intent(MissionListFullscreenActivity.this
						,PersonInfoActivity.class);
				intent.putExtra("uid", uid);
				intent.putExtra("token_id", token_id);
				intent.putExtra("token_key", token_key);
				
				
				MissionListFullscreenActivity.this
					.startActivityForResult(intent, 1);
			}
			
		});
		my_missions.setOnRefreshListener(new OnRefreshListener() {
			
			@Override
			public int onRefresh() {
				// TODO Auto-generated method stub
				Toast.makeText(context_this_activity,"没有东西了。。\no(>﹏<)o不要拉啦", Toast.LENGTH_SHORT).show();
				return 0;
			}
		});
		my_missions.setOnRefreshTailListener(new OnRefreshTailListener() {
			
			@Override
			public int onRefresh() {
				// TODO Auto-generated method stub
				return 0;
			}
		});
		RelativeLayout layout_this = (RelativeLayout)findViewById(R.id.fullscreen_content);
		my_missions.setOnTouchListener(new My_Gesture(context_this_activity,layout_this , 0));
		
		my_missions.setOnItemClickListener(new OnItemClickListener() {

			@Override
			public void onItemClick(AdapterView<?> arg0, View arg1, final int position,
					long arg3) {
				// TODO Auto-generated method stub
				
				final String obj_id = adapter.getItemObjId(position);
				final String my_email_id = new Personal_Info_database(context_this_activity).searchEmail(uid);
				
				if (position == 1){
					return ;
				}
				
				if (my_email_id != null){
					intent_to_talkoing = new Intent(MissionListFullscreenActivity.this,TalkActivity.class);
					intent_to_talkoing.putExtra("mission_id", obj_id);
					intent_to_talkoing.putExtra("uid", uid);
					MissionListFullscreenActivity.this.startActivity(intent_to_talkoing);
					
					
					/*
					new AlertDialog.Builder(MissionListFullscreenActivity.this)
									.setTitle("Archive Mission")
									.setMessage("Mission sucessful ?")
									.setPositiveButton("sure", new DialogInterface.OnClickListener(){

										@Override
										public void onClick(
												DialogInterface dialog,
												int which) {
											// TODO Auto-generated method stub
											MissionTag.archiveMission(context_this_activity, obj_id, my_email_id, new receiveSure() {
												
												@Override
												public void Sure(String info, String obj_id) {
													// TODO Auto-generated method stub
													adapter.reMoveData(position-2);
													new MissionDataBase(context_this_activity).del(MissionDataBase.TBL_NAME_MISSION, obj_id);
													new TempDataBase(context_this_activity).del(TempDataBase.TBL_NAME_MISSION, obj_id);
													Toast.makeText(context_this_activity, " mission \n Successful !!", Toast.LENGTH_SHORT).show();
													
												}
											});
										
										}
										
									})
									.show();
									
					*/
				}
			}
		});
		
		/**
		 * 	Delete mission
		 */
		my_missions.setOnItemLongClickListener(new OnItemLongClickListener() {

			@Override
			public boolean onItemLongClick(AdapterView<?> arg0, View arg1,
					final int position, long arg3) {
				// TODO Auto-generated method stub
				if (position == 1){
					return false;
				}
				final String obj_id = adapter.getItemObjId(position);
				Log.d("CACHE_TODELETE","Now all items :"+String.valueOf(adapter.getCount()));
				Log.d("CAHCE_to_delete", "this "+String.valueOf(position));
				Log.d("CACHE_todelet", "uid :"+uid);
				final String my_email_id = new Personal_Info_database(context_this_activity).searchEmail(uid);
				if(my_email_id != null){
					AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(MissionListFullscreenActivity.this);
					dialogBuilder
						.setTitle("sure ?")
						.setMessage("sure to remove this mission ?")
						.setPositiveButton("yes", new DialogInterface.OnClickListener() {
							
							@Override
							public void onClick(DialogInterface dialog, int which) {
								// TODO Auto-generated method stub
//								MissionTag.removeMission(context_this_activity,obj_id, my_email_id, new receiveSure() {
//									
//									@Override
//									public void Sure(String info, String obj_id) {
//										// TODO Auto-generated method stub
//										if (info.equals("ok")){
//											adapter.reMoveData(position-2);
//											new MissionDataBase(context_this_activity).del(MissionDataBase.TBL_NAME_MISSION, obj_id);
//											new TempDataBase(context_this_activity).del(TempDataBase.TBL_NAME_MISSION, obj_id);
//											Toast.makeText(context_this_activity, "remove such mission \n Successful !!", Toast.LENGTH_SHORT).show();
//									
//										}
//									}
//								});
								
								new MissionDataBase(context_this_activity).del(MissionDataBase.TBL_NAME_MISSION, obj_id);
								new TempDataBase(context_this_activity).del(TempDataBase.TBL_NAME_MISSION, obj_id);
								adapter.reMoveData(position);
								
								Intent intent = new Intent();
								intent.setAction(ARGUMENTS.REMOVE_ONE_TO_SERVICE);
								intent.putExtra(BroadCastRecevier.KEY, obj_id);
								//sendBroadCastTo(intent);
								
								Toast.makeText(context_this_activity, "remove such mission \n Successful !!", Toast.LENGTH_SHORT).show();
							}
						})
						.show();
				}else {
					
				}
				return false;
			}
		});
		
		
	}
	
	@Override
	protected void onResume() {
		// TODO Auto-generated method stub
		Log.d(tag,"resume ..");
//		String  email = new Personal_Info_database(context_this_activity).searchEmail(uid);
//		String pass = new Personal_Info_database(context_this_activity).searchPassword(uid);
//		Log.d(tag, "pass :"+pass);
		new PersonTag(context_this_activity,uid).LoadOwnInfo(token_id, token_key, my_name, my_picture);
		 
		super.onResume();
	}
	
	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		// TODO Auto-generated method stub
		if (keyCode == KeyEvent.KEYCODE_BACK){
//			Intent  intent_to_index = new Intent(MissionListFullscreenActivity.this,IndexFullscreenActivity.class);
//			intent_to_index.putExtra("uid", uid);
//			
			this.finish();
		}
		return false;
	}
	
//	private void sendBroadCastTo(Intent intent){
//		sendBroadcast(intent);
//	}
	//###########################################################
	//###########################################################
	//###########################################################
	//###########################################################
	//###########################################################
	
	@Override
	public void onActivityResult(int requestCode, int resultCode,Intent data){
		if (requestCode == 1 && data != null 
				&& resultCode == ARGUMENTS.ChoosePhotoCode){
			Uri select = data.getData();
			my_picture.setImageURI(select);
		}
	}
	
	/*######################################
	 * 
	 * this is adapter for my mission list 
	 *######################################
	 */
	class DragListAdapter extends BaseAdapter {
		private Context context_from_activity;
		private ArrayList<HashMap<String,String>> DATA = new ArrayList<HashMap<String,String>> ();
		private ArrayList<Bitmap>ImageDATA = new  ArrayList<Bitmap>();
		
		//component area
		private ImageView picture;
		private TextView name ;
		private TextView describe;
		private TextView mission_name ;
		private TextView mission_time;
		private TextView mission_place ;
		private TextView mission_attendees;
		private LinearLayout tagArea ;
		private ProgressBar progress;
		
		
		public DragListAdapter (Context context){
			this.context_from_activity = context;
			Log.d("CACHE", "LOAD Successful ...");
		}
		public void addData(ContentValues oneCrow){
			HashMap<String, String> oneMission = new HashMap<String, String>();
			oneMission.put(MissionDataBase.MISS_OBJ_ID, oneCrow.getAsString(MissionDataBase.MISS_OBJ_ID));
			oneMission.put(MissionDataBase.MISSION_NAME, oneCrow.getAsString(MissionDataBase.MISSION_NAME));
			oneMission.put(MissionDataBase.MISSION_TAG, oneCrow.getAsString(MissionDataBase.MISSION_TAG));
			oneMission.put(MissionDataBase.DESCRIBE, oneCrow.getAsString(MissionDataBase.DESCRIBE));
			
			
			oneMission.put(MissionDataBase.PLACE_NAME, oneCrow.getAsString(MissionDataBase.PLACE_NAME));
			oneMission.put(MissionDataBase.LATITUDE, oneCrow.getAsString(MissionDataBase.LATITUDE));
			oneMission.put(MissionDataBase.LONGITUDE, oneCrow.getAsString(MissionDataBase.LONGITUDE));
			
			oneMission.put(MissionDataBase.TIME_S, oneCrow.getAsString(MissionDataBase.TIME_S));
			oneMission.put(MissionDataBase.TIME_C, oneCrow.getAsString(MissionDataBase.TIME_C));
			
			oneMission.put(MissionDataBase.ACCESS_NUM, oneCrow.getAsString(MissionDataBase.ACCESS_NUM));
			oneMission.put(MissionDataBase.ATTENDEE, oneCrow.getAsString(MissionDataBase.ATTENDEE));
			
			oneMission.put(MissionDataBase.UP_NAME, oneCrow.getAsString(MissionDataBase.UP_NAME));
			
			DATA.add(oneMission);
			this.notifyDataSetChanged();
		}

		public void addData(ContentValues oneCrow,Bitmap image){
			HashMap<String, String> oneMission = new HashMap<String, String>();
			oneMission.put(MissionDataBase.MISS_OBJ_ID, oneCrow.getAsString(MissionDataBase.MISS_OBJ_ID));
			oneMission.put(MissionDataBase.MISSION_NAME, oneCrow.getAsString(MissionDataBase.MISSION_NAME));
			oneMission.put(MissionDataBase.MISSION_TAG, oneCrow.getAsString(MissionDataBase.MISSION_TAG));
			oneMission.put(MissionDataBase.DESCRIBE, oneCrow.getAsString(MissionDataBase.DESCRIBE));
			
			
			oneMission.put(MissionDataBase.PLACE_NAME, oneCrow.getAsString(MissionDataBase.PLACE_NAME));
			oneMission.put(MissionDataBase.LATITUDE, oneCrow.getAsString(MissionDataBase.LATITUDE));
			oneMission.put(MissionDataBase.LONGITUDE, oneCrow.getAsString(MissionDataBase.LONGITUDE));
			
			oneMission.put(MissionDataBase.TIME_S, oneCrow.getAsString(MissionDataBase.TIME_S));
			oneMission.put(MissionDataBase.TIME_C, oneCrow.getAsString(MissionDataBase.TIME_C));
			
			oneMission.put(MissionDataBase.ACCESS_NUM, oneCrow.getAsString(MissionDataBase.ACCESS_NUM));
			oneMission.put(MissionDataBase.ATTENDEE, oneCrow.getAsString(MissionDataBase.ATTENDEE));
			
			oneMission.put(MissionDataBase.UP_NAME, oneCrow.getAsString(MissionDataBase.UP_NAME));
			
			
			
			DATA.add(oneMission);
			ImageDATA.add(image);
			this.notifyDataSetChanged();
		}
		
		public void reMoveData(int position){
			
			DATA.remove(position-2);
			this.notifyDataSetChanged();
		}
		@Override
		public int getCount() {
			// TODO Auto-generated method stub
			return DATA.size();
		}

		@Override
		public HashMap<String,String> getItem(int position) {
			// TODO Auto-generated method stub
			return DATA.get(position);
		}
		
		public String getItemObjId(int position){
			if(position >=2 ){
				String mission_id = null;
				Log.d("CACHE", String.valueOf(position) + " all :"+String.valueOf(this.getCount()));
				mission_id = DATA.get(position -2).get(MissionDataBase.MISS_OBJ_ID);
				Log.d("CACHE","obj id : "+mission_id);
				return mission_id;
			}else{
				return null;
			}
		}
		@Override
		public long getItemId(int position) {
			// TODO Auto-generated method stub
			return position;
		}

		@Override
		public View getView(int position, View listView, ViewGroup parent) {
			// TODO Auto-generated method stub
			LayoutInflater inflater = (LayoutInflater) this.context_from_activity
					.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
			listView = inflater.inflate(R.layout.my_list_item, null);

			tagArea = (LinearLayout) listView.findViewById(R.id.my_list_mission_tag);
			
			picture = (ImageView) listView.findViewById(R.id.my_list_image_header);
			name = (TextView)listView.findViewById(R.id.my_list_text_people_nico);
			describe = (TextView) listView.findViewById(R.id.my_list_text_describe);
			progress = (ProgressBar)listView.findViewById(R.id.my_list_progress);
			mission_name = (TextView)listView.findViewById(R.id.my_list_mission_name);
			mission_place = (TextView)listView.findViewById(R.id.my_list_mission_place);
			mission_time = (TextView)listView.findViewById(R.id.my_list_mission_time);
			mission_attendees = (TextView)listView.findViewById(R.id.my_list_mission_attendee);
			
			String tags = DATA.get(position).get(MissionDataBase.MISSION_TAG); 
			String mNameString = DATA.get(position).get(MissionDataBase.MISSION_NAME);
			String mPlaceString = DATA.get(position).get(MissionDataBase.PLACE_NAME);
			
			Log.d("CACHE", "all : "+ String.valueOf(this.getCount())+"this is :"+String.valueOf(position));
			Log.d("CACHE", DATA.get(position).toString());
			
			int mLat = Integer.valueOf(DATA.get(position).get(MissionDataBase.LATITUDE));
			int mLon = Integer.valueOf(DATA.get(position).get(MissionDataBase.LONGITUDE));
			String mDescribeString = DATA.get(position).get(MissionDataBase.DESCRIBE);
			String mAttendeeString  =DATA.get(position).get(MissionDataBase.ATTENDEE);
			String mTimeString = DATA.get(position).get(MissionDataBase.TIME_S);
			String mTimeContnue = DATA.get(position).get(MissionDataBase.TIME_C);
			String upNameString = DATA.get(position).get(MissionDataBase.UP_NAME);
			float S_time =(float) Long.valueOf(mTimeString);
			int progressInt = 0;
			float N_time =(float) System.currentTimeMillis();
			try{
				float C_time =(float) TimeHelper.ParaTimeByStringH(mTimeContnue);
				progressInt =(int) ( ( (N_time - S_time) / C_time) *100 );
			}catch (NumberFormatException e){
				Log.d(tag, e.toString());
			}
			
			
			
			Log.d("CACHE","进度 :"+ String.valueOf(progressInt));
			Log.d("CACHE","tag :"+tags.toString());
			String[] TAGS = tags.split(" ");
			tagArea.removeAllViews();
			for (String item : TAGS){
				Log.d("CACHE","Tag item :" +item);
				LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT
						, LinearLayout.LayoutParams.WRAP_CONTENT);
				lp.setMargins(6, 0, 0, 0);
				TextView tv = new TextView(MissionListFullscreenActivity.this);
				tv.setText(item);
				tv.setLayoutParams(lp);
				tv.setPadding(6, 0, 0, 0);
				tv.setBackgroundResource(R.drawable.shape_deepskyblue_corner);
				tagArea.addView(tv);

				
			}
			
			
			if (ImageDATA.get(position) != null){
				picture.setImageBitmap(ImageDATA.get(position));
			}
			name.setText(upNameString);
			describe.setText(mDescribeString+"\n");
			mission_attendees.setText(mAttendeeString);
			mission_name.setText(mNameString);
			mission_time.setText(TimeHelper.paraTimeByLong(Long.valueOf( mTimeString )));
			mission_place.setText(mPlaceString);
			
			
			if (progressInt <= 100){
				progress.setProgress(progressInt);
			}
			
			return listView;
		}
		
	}
	
	
	
	
	/**
	 * 	load all info into view adapter,witch found in MissionDb .
	 */
	private  static void ParaMissionFromWeb(DragListAdapter adapter ,String mission_id){
		ContentValues mission = new MissionDataBase(context_this_activity).getMission(mission_id);
		try{
			String picture = mission.getAsString(MissionDataBase.PICTURE);
			Log.d("CACHE","i found picture in DB : "+picture);
			Bitmap bitmap = BitmapFactory.decodeFile(picture);
			adapter.addData(mission, bitmap);
		}catch (NullPointerException e){
			Log.d("CACHE", "nothing found in DB");
			adapter.addData(mission);
		}
	}

	private void  ParaMissionFromDb(DragListAdapter adapter ,String mission_id){
		ArrayList<String> IDS = new MissionDataBase(context_this_activity).getObjectIds();
		if(IDS != null){
			for (String obj_id : IDS){
				ContentValues mission = new MissionDataBase(context_this_activity).getMission(obj_id);
				try{
					String picture = mission.getAsString(MissionDataBase.PICTURE);
					Log.d("CACHE","i found picture in DB : "+picture);
					Bitmap bitmap = BitmapFactory.decodeFile(picture);
					adapter.addData(mission, bitmap);
				}catch (NullPointerException e){
					Log.d("CACHE", "no picture  found in DB");
					adapter.addData(mission);
				}
			}
		}else {
			Toast.makeText(context_this_activity, "o(╯□╰)o 现在没有任务了的说。。去接点吧╰(￣▽￣)╮", Toast.LENGTH_SHORT).show();
		}
		
	}
	
	
	
	
	//#############################################################
	
	//#############################################################
	
	//#############################################################
	
	//#############################################################
	//class area
	class My_Gesture extends GestureListener {
		RelativeLayout layout ;
		private int FirstX ;
		private int FinalX;
		private int LeftDistance ;
		public My_Gesture(Context context,RelativeLayout layout ,int leftMove) {
			super(context);
			// TODO Auto-generated constructor stub
			this.layout = layout;
			this.LeftDistance = leftMove;
		}
		
		
		@Override
		public boolean FinallyMove(String tag) {
			// TODO Auto-generated method stub
			Log.d(tag, "side :"+tag);
			if (tag.equals("left")){
				layout.setPadding(0, 0,0 , 0);
			}
			if (tag.equals("right")){
				layout.setPadding(LeftDistance - 400, 0, 0, 0);
			}
			
			return false;
		}
		
		@Override
		public boolean FirstMove(int dowX) {
			// TODO Auto-generated method stub
			this.FirstX = dowX;
			
			return false;
		}
		
	}

}
